import { Observable,AsyncSubject,interval } from 'rxjs';
import { take,tap } from 'rxjs/operators'

console.log(Date.now());
const observable:Observable<any> = interval(1000);
const observableTake:Observable<any> = observable.pipe(take(4));

const subject:AsyncSubject<any> = new AsyncSubject();

subject.subscribe(
  {
    next:(value:any) => {
      console.log('[1]###next###');
      console.log(Date.now());
      console.log(typeof(value));
      console.log(value);
    },
    complete:() => {
      console.log('[1]###complete###');
    },
    error:(error:any) => {
      console.log('[1]###error###');
      console.log(error);
    }
  }
);

observableTake.subscribe(subject);

setTimeout(() => {
  subject.subscribe(
    {
      next:(value:any) => {
        console.log('[2]###next###');
        console.log(Date.now());
        console.log(typeof(value));
        console.log(value);
      },
      complete:() => {
        console.log('[2]###complete###');
      },
      error:(error:any) => {
        console.log('[2]###error###');
        console.log(error);
      }
    }
  );
},5000);